package com.human.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.human.server.entity.Attendance;
import com.human.server.model.request.AttendanceExcel;
import com.human.server.service.AttendanceService;
import com.human.server.mapper.AttendanceMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
* @author Admin
* @description 针对表【attendance(考勤记录表)】的数据库操作Service实现
* @createDate 2025-09-09 00:07:15
*/
@Service
public class AttendanceServiceImpl extends ServiceImpl<AttendanceMapper, Attendance>
    implements AttendanceService{

    public void upload(MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), AttendanceExcel.class, new ReadListener<AttendanceExcel>(){

            @Override
            public void invoke(AttendanceExcel attendanceExcel, AnalysisContext analysisContext) {
                Attendance attendance = new Attendance();
                BeanUtil.copyProperties(attendanceExcel, attendance);
                baseMapper.insert(attendance);
            }

            @Override
            public void doAfterAllAnalysed(AnalysisContext analysisContext) {

            }
        }).sheet().doRead();
    }
}




